package org.icosagon.core.magic;

import java.util.HashMap;
import java.util.Vector;
import org.icosagon.core.InvalidNumberException;

/**
 *
 * @author Daniel Owens
 */
public class SpellChart {
    private Vector<Spell> spells = new Vector<Spell>(10, 10);
    private HashMap<Integer, Integer> prepared = new HashMap<Integer, Integer>();
    private boolean spontaneous = false;

    public Vector<Spell> getSpells() {
        return this.spells;
    }

    public Vector<Spell> getSpellsByLevel(int lvl) {
        Vector<Spell> temp = new Vector<Spell>(10, 10);
        for(Spell spell : this.spells) {
            if(spell.getLevel() == lvl)
                temp.add(spell);
        }
        if(temp.isEmpty())
            return null;
        return temp;
    }

    public void addNumberOfPreparedSpells(int level, int value) {
        if(level < 0 || value < 0)
            throw new InvalidNumberException("Parameters can not be negative.");
        Integer key = new Integer(level);
        value = this.prepared.get(key).intValue() + value;
        this.prepared.put(key, value);
        key = null; //cleanup
    }

    public void decreaseNumberOfPreparedSpells(int level, int value) {
        if(level < 0 || value < 0)
            throw new InvalidNumberException("Parameters can not be negative.");
        Integer key = new Integer(level);
        value = this.prepared.get(key).intValue() - value;
        this.prepared.put(key, value);
        key = null; //cleanup
    }

    public void incrementNumberOfPreparedSpells(int level) {
        this.addNumberOfPreparedSpells(level, 1);
    }

    public int getNumberOfPreparedSpells(int level) {
        if(level < 0)
            throw new InvalidNumberException("Parameter can not be negative.");
        return this.prepared.get(new Integer(level)).intValue();
    }

    public int getNumberOfPreparedSpells() {
        int total = 0;
        for(Integer i : this.prepared.values()) {
            total += i.intValue();
        }
        return total;
    }

    public void setSpells(Vector<Spell> spell) {
        this.spells = spell;
    }

    public void removeSpell(Spell spell) {
        this.spells.remove(spell);
    }

    public void addSpell(Spell spell) {
        this.spells.add(spell);
    }

    public boolean isEmpty() {
        return this.spells.isEmpty();
    }

    public void setSpontaneous(boolean value) {
        this.spontaneous = value;
    }

    public boolean isSpontaneous() {
        return this.spontaneous;
    }
}